home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / manageme / tcpdump-.7 / tcpdump- / tcpdump-richard-1.7 / tcpdump-3.0 / print-null.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-09  |  2.7 KB  |  113 lines

  1. /*
  2.  * Copyright (c) 1991, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  */
  21.  
  22. #ifndef lint
  23. static char rcsid[] =
  24.     "@(#)$Header: print-null.c,v 1.14 94/06/10 17:01:35 mccanne Exp $ (LBL)";
  25. #endif
  26.  
  27. #include <sys/param.h>
  28. #include <sys/time.h>
  29. #include <sys/socket.h>
  30. #include <sys/file.h>
  31. #include <sys/ioctl.h>
  32.  
  33. #include <net/if.h>
  34.  
  35. #include <netinet/in.h>
  36. #include <netinet/in_systm.h>
  37. #include <netinet/ip.h>
  38. #include <netinet/if_ether.h>
  39. #include <netinet/ip_var.h>
  40. #include <netinet/udp.h>
  41. #include <netinet/udp_var.h>
  42. #include <netinet/tcp.h>
  43. #include <netinet/tcpip.h>
  44.  
  45.  
  46. #include <stdio.h>
  47. #include <string.h>
  48.  
  49. #include "interface.h"
  50. #include "addrtoname.h"
  51. #include "pcap.h"
  52.  
  53. #define    NULL_HDRLEN 4
  54.  
  55. static void
  56. null_print(const u_char *p, const struct ip *ip, int length)
  57. {
  58.     u_int family;
  59.  
  60.     bcopy(p, &family, sizeof(family));
  61.  
  62.     if (nflag) {
  63.         /* XXX just dump the header */
  64.         return;
  65.     }
  66.     switch (family) {
  67.  
  68.     case AF_INET:
  69.         printf("ip: ");
  70.         break;
  71.  
  72.     case AF_NS:
  73.         printf("ns: ");
  74.         break;
  75.  
  76.     default:
  77.         printf("AF %d: ", family);
  78.         break;
  79.     }
  80. }
  81.  
  82. void
  83. null_if_print(u_char *user, const struct pcap_hdr *h, const u_char *p)
  84. {
  85.     int length = h->len;
  86.     int caplen = h->caplen;
  87.     const struct ip *ip;
  88.  
  89.     ts_print(&h->ts);
  90.  
  91.     /*
  92.      * Some printers want to get back at the link level addresses,
  93.      * and/or check that they're not walking off the end of the packet.
  94.      * Rather than pass them all the way down, we set these globals.
  95.      */
  96.     packetp = p;
  97.     snapend = p + caplen;
  98.  
  99.     length -= NULL_HDRLEN;
  100.  
  101.     ip = (struct ip *)(p + NULL_HDRLEN);
  102.  
  103.     if (eflag)
  104.         null_print(p, ip, length);
  105.  
  106.     ip_print((const u_char *)ip, length);
  107.  
  108.     if (xflag)
  109.         default_print((const u_char *)ip, caplen - NULL_HDRLEN);
  110.     putchar('\n');
  111. }
  112.  
  113.